import { createStore } from "vuex"

export default createStore({
  state() {
    return {
      token: sessionStorage.getItem('token') || '',
      menuList: JSON.parse(sessionStorage.getItem('menuList')) || []
    }
  },
  getters: {
    // 获取 token
    getToken: (state) => {
      return state.token
    },
    getMenuList: (state) => {
      return state.menuList
    }
  },
  mutations: {
    // 设置 token
    setToken (state, token) {
      sessionStorage.setItem('token', token)
      state.token = token
    },
    setMenuList(state, menuList) {
      sessionStorage.setItem('menuList', JSON.stringify(menuList))
      state.menuList = menuList
    }
  },
  actions: {}
})